﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using VideoClassLibrary.Extension;
using VideoClassLibrary.Model;
using VideoClassLibrary.BusinessLogicLayer;
public partial class TrainClassManagement_AddTrainClass : AdminUserBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        Ajax.Utility.RegisterTypeForAjax(typeof(AjaxMethodHelper));
        if (!IsPostBack)
        {
            TeacherModule ta = new TeacherModule();
            List<V_School> vs = new List<V_School>();
            this.hfSchoolID.Value = this.SchoolID.ToString();
            vs = ta.GetSchool();
            dlschool.DataSource = vs;
            dlschool.DataBind();
            dlschool.SelectedValue = this.CurrentUser.SchoolID.ToString();
            dlschool.Enabled = false;
           
        }
        if (!string.IsNullOrEmpty(Request.QueryString["VTC_Number"]))
        {

            TrainClassNum();
        }
    }

    protected void btnReg_Click(object sender, EventArgs e)
    {
        if (!new TrainClassModule().IsTrainClassNumBySchoolId(this.SchoolID, this.txtvtcNum.Value))
        {
            Response.Write("<script> alert('培训班编号已存在，请重新输入培训班编号！')</script>");
        }
        else
        {
            V_TrainClass trainclass = new V_TrainClass();
            TrainClassModule tm = new TrainClassModule();
            trainclass.Create_time = DateTime.Now;
            trainclass.VTC_Number = this.txtvtcNum.Value;
            trainclass.MaxUserCount = Convert.ToInt32(this.txtMaxCount.Text);
            trainclass.SchoolID = Convert.ToInt32(dlschool.SelectedValue);
            trainclass.update_time = DateTime.Now;
            trainclass.VTC_desc = txtTrainMessage.Text.ToString();
            trainclass.VTC_name = txtTrainClasseName.Text.Trim();
            trainclass.VTC_StartDate = Convert.ToDateTime(this.txtStarDate.Text.Trim());
            trainclass.VTC_EndDate = Convert.ToDateTime(this.txtEndDate.Text.Trim());
            trainclass.IsPublish = this.chkIsEnable.Checked ? 1 : 0;
             
            if (tm.AddTrainclass(trainclass)==1)
            {
                PageHelper.AlterMsgAndRedirect("添加培训班成功！", "ViewTrainingClassList.aspx");
            }
            else
            { Label1.Text = "添加培训班失败！"; }
        }
    }

    private void TrainClassNum()
    {
        string Num = Request.QueryString["VTC_Number"].ToString();        
        TrainClassModule tm = new TrainClassModule();
        bool b = tm.IsTrainClassNumBySchoolId(this.SchoolID, Num);
        //Response.Write(b.ToString());
    }
    protected void txtMaxCount_TextChanged(object sender, EventArgs e)
    {
       if(!StringUtils.IsNumeric(txtMaxCount.Text))
       {
           ltrChk.Visible = true;
           btnReg.Enabled = false;
       }else
       {
           btnReg.Enabled = true;
       }
    }
}
